import React, { Component } from 'react';
import { connect } from 'react-redux';
import Dynamic_table from './Dynamic_table';
import { Button, Select, Input } from "antd";
import Dynamic_add from './Dynamic_add';
import action from '../../store/action';
import { openNotification } from '../../component/Notification';
import { onkeyDown } from '../../store/function';

const { Option } = Select;
const { Search } = Input;
const data = ['动态', '公告', '最新数据', '最新标准', '最新资源', '最新案例', '热门检索', '材料性能数据', '测试方法', '测试规范'];

class index extends React.Component {
    constructor() {
        super();
        this.state={
            select_val:'',
            input_val:''

        }
    }
    render() {
        return <div>
            <div>
                <div className="search_div">
                    标题:
                    <Search placeholder="请输入关键字" className="search_input" onChange={(e) => this.handleChange(e)} onKeyUp={(e)=>onkeyDown(e,this.handel_search)}></Search>
                    查询类型:
                    <Select  defaultValue='请选择' style={{ width: 120 ,margin:'0 10px'}} onChange={this.handleProvinceChange}>
                        {data.map((item,index)=> (
                            <Option key={index+1}>{item}</Option>
                        ))}
                    </Select>
                    <Button type="primary" className='search_btn' style={{ background: '#FB6137', borderColor: '#FB6137' }} onClick={this.handel_search}>搜索</Button>

                </div>
            </div>
            <Dynamic_add/>
            <Dynamic_table />
        </div>
    }
    handleProvinceChange=(e)=>{
        this.setState({
            select_val:e
        })
    }
    handleChange=(val)=>{
        this.setState({
            input_val:val.target.value
        })
    }
    handel_search=()=>{
        let list={
            title:this.state.input_val,
            type:this.state.select_val
        }
      if(list.title!=''&&list.type!=''){
        this.$axios.get(`/manager/api/pageGetDynamicAnnouncement/0/9999?title=${list.title}&type=${list.type}`).then((res) => {
            if(res.status===1){
              const {dynamic_search}=this.props;
              dynamic_search(res.dynamicAnnouncementList)
            }
          }).catch((err) => {
              console.log(err);
          })
      }else{
          return openNotification('搜索内容请填完整!')
      }
    }
}

export default connect(state=>({...state.custom}),action.custom)(index);